#include "stdafx.h"
#include "UserInterface.h"

using namespace std;

UserInterface::UserInterface(GUISystem& guiSystem) : m_guiSystem(guiSystem)
{
}


UserInterface::~UserInterface()
{
}


void UserInterface::AddControl(shared_ptr<GUIObject> pObject)
{
    if (pObject)
    {
        m_guiObjects.push_back(pObject);
        m_guiSystem.AddControl(pObject);
    }
}

void UserInterface::RemoveControl(shared_ptr<GUIObject> pObject)
{
    if (pObject)
    {
        auto it = find(m_guiObjects.begin(), m_guiObjects.end(), pObject);

        if (it != m_guiObjects.end())
        {
            m_guiSystem.RemoveControl(pObject);
            m_guiObjects.erase(it);
        }
    }
}

void UserInterface::Hide()
{
    for (auto& pObject : m_guiObjects)
    {
        pObject->Hide();
    }
}

void UserInterface::Show()
{
    for (auto& pObject : m_guiObjects)
    {
        pObject->Show();
    }
}

void UserInterface::Destroy(GameEngine& gameEngine)
{
    for (auto& pObject : m_guiObjects)
    {
        m_guiSystem.RemoveControl(pObject);
    }

    m_guiObjects.clear();
}
